from myapp import db
from datetime import datetime

class OnLine(db.Model):
    __tablename__ = 'sys_online'
    id = db.Column(db.String(36), primary_key=True)
    create_time = db.Column(db.DateTime, index=True, default=datetime.now)
    login_name = db.Column(db.String(100))
    ip = db.Column(db.String(100))
    type = db.Column(db.String(1))

    def get_id(self):
        return str(self.ID)

    def __repr__(self):
        return '<Oneline %r>\n' %(self.login_name)

    def to_json(self):
        return {
            'infoId': self.id,
            'createTime': self.create_time.strftime('%Y-%m-%d %H:%M:%S'),
            'loginName': self.login_name,
            'ipaddr': self.ip,
            'type': self.type
        }   